<label class="item-label">{$field.title|htmlspecialchars}
    <if condition="$field['subtitle']">
        <span class="check-tips">（{$field.subtitle|htmlspecialchars}）</span>
    </if>
</label>
<if condition="$field['name'] == 'action'">
    <p style="color: #f00;">开发人员注意：你使用了一个名称为action的字段，由于这个字段名称会与form[action]冲突，导致无法提交表单，请换用另外一个名字。</p>
</if>
<div class="controls ">
    <switch name="field.type">
        <case value="text">
            <input type="text" name="{$field.name}"  value="{$field.value|htmlspecialchars}" class="text input-large form-control" style="width: 400px"/>
        </case>
        <case value="hidden">
            <input type="hidden" name="{$field.name}" value="{$field.value}" class="text input-large"/>
        </case>
        <case value="readonly">
            <input type="text" name="{$field.name}" value="{$field.value}" class="text input-large form-control" style="width: 400px" placeholder="无需填写" readonly/>
        </case>
        <case value="integer">
            <input type="text" name="{$field.name}" value="{$field.value}" class="text input-large form-control" style="width: 400px"/>
        </case>
        <case value="uid">
            <input type="text" name="{$field.name}" value="{$field.value}" class="text input-large form-control" style="width: 100px"/>
        </case>
        <case value="select">
            <select name="{$field.name}" class="form-control" style="width:auto;">
                <volist name="field.opt" id="option">
                    <php>
                        $selected = $field['value']==$key ? 'selected' : '';
                    </php>
                    <option value="{$key}" {$selected}>{$option|htmlspecialchars}</option>
                </volist>
            </select>
        </case>
        <case value="radio">
            <volist name="field.opt" id="option">
                <php>
                    $checked = $field['value']==$key ? 'checked' : '';
                    $inputId = "id_$field[name]_$key";
                </php>
                <label for="{$inputId}"> <input id="{$inputId}" name="{$field.name}" value="{$key}" type="radio" {$checked}/>
                    {$option|htmlspecialchars}</label>
            </volist>
        </case>
        <case value="image">
            <div class="controls">
                <input type="file" id="upload_picture_{$field.name}">
                <input type="hidden" name="{$field.name}" id="cover_id_{$field.name}" value="{$field['value']}"/>
                <div class="upload-img-box">
                    <notempty name="field.value">
                        <div class="upload-pre-item"><img src="{$field.value|get_cover='path'}"/></div>
                    </notempty>
                </div>
            </div>
            <script type="text/javascript">
                //上传图片
                /* 初始化上传插件 */
                $("#upload_picture_{$field.name}").uploadify({
                    "height"          : 30,
                    "swf"             : "__STATIC__/uploadify/uploadify.swf",
                    "fileObjName"     : "download",
                    "buttonText"      : "上传图片",
                    "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                    "width"           : 120,
                    'removeTimeout'	  : 1,
                    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                    "onUploadSuccess" : uploadPicture{$field.name},
                'onFallback' : function() {
                    alert('未检测到兼容版本的Flash.');
                }
                });
                function uploadPicture{$field.name}(file, data){
                    var data = $.parseJSON(data);
                    var src = '';
                    if(data.status){
                        $("#cover_id_{$field.name}").val(data.id);
                        src = data.url || '__ROOT__' + data.path
                        $("#cover_id_{$field.name}").parent().find('.upload-img-box').html(
                                '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                        );
                    } else {
                        updateAlert(data.info);
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                            $(that).removeClass('disabled').prop('disabled',false);
                        },1500);
                    }
                }
            </script>

        </case>
        <case value="checkbox">
            <php>
                $importCheckBox = true;
            </php>
            <php>
                $field['value_array'] = explode(',', $field['value']);
            </php>
            <volist name="field.opt" id="option">
                <php>
                    $checked = in_array($key,$field['value_array']) ? 'checked' : '';
                    $inputId = "id_$field[name]_$key";
                </php>
                <label for="{$inputId}"> <input type="checkbox" value="{$key}" id="{$inputId}" class="oneplus-checkbox" data-field-name="{$field.name}" {$checked}/>
                    {$option|htmlspecialchars}</label>
                <input type="hidden" name="{$field.name}" class="oneplus-checkbox-hidden" data-field-name="{$field.name}" value="{$field.value}"/>
            </volist>
        </case>
        <case value="editor">
            <label class="textarea">
                <textarea name="{$field.name}" class="form-control" style="width: 400px;height: 200px">{$field.value|htmlspecialchars}</textarea>
                {:hook('adminArticleEdit', array('name'=>$field['name'],'value'=>$field['value']))}
            </label>
        </case>
        <case value="textarea">
            <textarea name="{$field.name}" class="text input-large form-control" style="height: 8em;width: 400px;height: 200px">{$field.value|htmlspecialchars}</textarea>
        </case>
        <case value="time">
            <php>
                $importDatetimePicker = true;
                //默认为当前时间
                if(!$field['value']){
                $field['value'] = time();
                }
            </php>
            <input type="hidden" name="{$field.name}" value="{$field.value}"/>
            <input type="text" data-field-name="{$field.name}" class="text input-large time form-control" style="width: 400px" value="{$field.value|time_format}" placeholder="请选择时间" />
        </case>
        <default/>
        <span style="color: #f00;">错误：未知字段类型 {$field.type}</span>
        <input type="hidden" name="{$field.name}" value="{$field.value|htmlspecialchars}"/>
    </switch>
</div>